﻿namespace SCABaselineCS.Tests.Reliability
{
    using System;
    using System.Text;
    using System.Collections.Generic;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using System.Collections.ObjectModel;
    using System.Linq;

    [TestClass]
    public class ReadOnlyCollectionTests
    {
        // these are the result of a warning that
        //  priv readonly list<string> _x
        //  pub list<string> x { return new list<string>(_x.select(a => String.Copy(a))) }
        // would return a modifable list that was otherwise marked readonly.
        // so, in here should be all the different ways that a list might be exposed

        private List<string> ModifiableList;
        private ReadOnlyCollection<string> ModifableReadOnlyList; // probably not necessary, since it's only exposed via getter
        private readonly List<string> ReadOnlyModifiableList; // = new List<string>();
        private readonly ReadOnlyCollection<string> ReadOnlyList; // = new instance

        public List<string> ExposedModifiableList { get { return this.ModifiableList; } }
        public List<string> ExposedReadOnlyModifiableList { get { return this.ReadOnlyModifiableList; } }
        public List<string> ExposedReadOnlyList { get { return this.ReadOnlyModifiableList; } }
        public List<string> CopiedList { get { return new List<string>(this.ModifiableList.Select(a => String.Copy(a))); } }


        // TODO : the assertions here will need to spend some time building the datasets, attempting
        //        to modify, then performing deep inspection of the results.

        //[TestMethod]
        public void TestMethod1()
        {
            // Arrange

            // Act

            // Assert
        }






        //
        public class a
        {
            // I would prefer to put an initizer or something here, but doing so might impact test results
            public List<string> MyReadonlyList { get; }
        }


        public void ReadOnlyListsCannotBeNull()
        {
            // arrange
            var instance = new a();

            // act
            var action = new Action(() => instance.MyReadonlyList.Clear());

            // assert
            // this should not throw a warning about instance.MyList being null (while attempting to call Clear method),
            // since the lack of a setter means that there's nothing I can do about it

            // in theory, an analyzer could examine the ctor(s), call list, etc... to see if it's ever initialized.
        }



    } // class
} // namespace